package Demo0;

import java.io.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;

public class worldCup {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        Map<String,String> worldcup=new HashMap<String,String>();
        worldcup.put("1998","法国");
        worldcup.put("2002","巴西");
        worldcup.put("2006","意大利");
        worldcup.put("2010","西班牙");
        worldcup.put("2014","德国");
        BufferedWriter bw=null;
        Iterator<Map.Entry<String, String>> entryIt = worldcup.entrySet().iterator();
        try {
             bw=new BufferedWriter(new FileWriter("E:\\22\\worldcup.txt"));
            while (entryIt.hasNext()) {
              Map.Entry<String, String> entry = entryIt.next();
              bw.write(entry.getKey()+"/"+entry.getValue());
              bw.newLine();
              bw.flush();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            try {
                if(bw!=null){
                    bw.close();
                    bw=null;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.out.println("请输入一个年份：");
        String year=input.next();
        StringBuffer buffer=new StringBuffer();
        BufferedReader reader=null;
        try {
            reader=new BufferedReader(new FileReader("E:\\22\\worldcup.txt"));
            String line;
            while((line=reader.readLine())!=null){
                buffer.append(line);
               if(worldcup.containsKey(year)){
                  String value=worldcup.get(year);
                   System.out.println(value+"夺得了世界杯冠军");
                   break;
               }else{
                   System.out.println("未举办世界杯");
                   break;
               }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally{
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
